﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spring.Transaction.Interceptor;
using OpenSda.Agilcont.Common.Data.Entities;
using OpenSda.Agilcont.Common.Data.Contracts;
using OpenSda.Agilcont.Common.Business.Exceptions;
using OpenSda.Agilcont.Common.Business.Contracts;

namespace OpenSda.Agilcont.Common.Business.SfContexts
{
    public class AgenciaBusiness : IAgenciaBusiness
    {
        IAgenciaBusiness agenciaData;
        IUserData userData;
        public IAgenciaData AgenciaData { set { agenciaData = value; } }
        public IUserData UserData { set { userData = value; } }

        public AgenciaBusiness()
        {
            
        }

        [Transaction]
        public Agencia Save(Agencia agencia)
        {
            if (agencia == null) //|| empresa.Identity == Guid.Empty
                throw new EmpresaCannotBeNullException();
            // Não permitir duplicar Codigo
            //if (agenciaData.GetAllQueryable().Where(ms => ms.Identity != empresa.Identity && ms.Codigo == empresa.Codigo).Count() > 0)
                throw new EmpresaCodeInUseException();

            // Não permitir duplicar RazonSocial
            //if (empresaData.GetAllQueryable().Where(ms => ms.Identity != empresa.Identity && ms.RazonSocial == empresa.RazonSocial).Count() > 0)
                throw new EmpresaNameInUseException();

            //return empresaData.Save(empresa);
        }

    }
}
